import React, { useState } from "react";
import Taro, { useReady } from "@tarojs/taro";
import http from "../../http/http";
import { useEffect } from "react";
import { View, Text } from "@tarojs/components";
import "./home.less";
import "../../fonts/remixicon.less";
import HomeBanner from "./component/HomeBanner";
import HomeCategory from "./component/HomeCategory";
import HotSale from "./component/HotSale";
import ProductList from "./component/ProductList";
import homeData from "../../state/homeData";
import { observer } from "mobx-react";

function Home() {
  useReady(() => {
    http({
      url: "/huyuxin/getbanner",
      method: "get",
      data: {}
    }).then(res => {
      // console.log(res);
      homeData.setBannerList(res.data);
    });

    http({
      url: "/huyuxin/gethotsell",
      method: "post",
      data: {
        limit: 5
      }
    }).then(res => {
      // console.log(res);
      homeData.setHotSellList(res.data);
    });

    http({
      url: "/huyuxin/getgoods/classify",
      method: "get",
      data: {}
    }).then(res => {
      // console.log(res);
      homeData.setGoodsClass(res.data);
    });

    http({
      url: "/huyuxin/getcomp",
      method: "get",
      data: {}
    }).then(res => {
      // console.log(res);
      homeData.setCompList(res.data);
    });

    http({
      url: "/huyuxin/getbigprice",
      method: "get",
      data: {}
    }).then(res => {
      // console.log(res);
      homeData.setPriceHight(res.data);
    });

    http({
      url: "/huyuxin/gethotsell",
      method: "post",
      data: {
        limit: 60
      }
    }).then(res => {
      // console.log(res);
      homeData.setSellHight(res.data);
    });
  });

  return (
    <View className="c-home-page">
      <HomeBanner />
      <HomeCategory />
      <HotSale />
      <ProductList />
    </View>
  );
}

export default observer(Home);
